package com.google.code.coma;

import com.google.code.coma.domain.Type;
import com.google.code.coma.producer.RmiProducer;
import com.google.code.coma.producer.SpaceProducer;
import com.google.code.coma.producer.StandaloneProducer;
import com.google.code.coma.producer.publisher.SpacePartPublisher;

/**
 * @author Dominik Strasser, dominikstr@gmail.com
 */
public class ProducerLauncher {
	public static void main(String... args) {
		//perform some checks
		if (args.length != 5) {
			System.out.println("Usage: <SPACE|RMI> <type of part> <amount> <fault percantage> <factoryId>");
			return;
		}
		Type t;
		int amount;
		int fault;
		try {
			t = Type.valueOf(args[1]);
		} catch (IllegalArgumentException e) {
			System.out.println("<type> has to be one of " + Type.values());
			return;
		}
		try {
			amount = Integer.valueOf(args[2]);
		} catch (NumberFormatException e) {
			System.out.println(args[2] + " isn't a number");
			return;
		}
		try {
			fault = Integer.valueOf(args[3]);
			if (fault < 0 || fault > 100) throw new NumberFormatException("must be between 0 and 100");
		} catch (NumberFormatException e) {
			System.out.println(args[3] + " isn't a valid number");
			return;
		}
		//start the producer
		if (args[0].equals("SPACE"))
			new SpaceProducer(args[4], amount, t, fault,false).startWork();
		else if (args[0].equals("RMI"))
			new RmiProducer(args[4], amount, t, fault,false).startWork();
		else
			System.out.println("Unkown operation mode: " + args[0]);
	}
}
